package com.talkweb.securitycamera.utils.eventlib.communicationevent;


import com.talkweb.securitycamera.utils.eventlib.pool.AsynEventPools;

/**
 * @version 1.0.1
 * @description:事件模型
 * @program:
 * @Author xiaozhijun
 * @Date 2020/12/22 17:02
 */
public class PhotoEvent implements IEventReset {

    //对象池
    private static AsynEventPools<PhotoEvent> sPool = new AsynEventPools<PhotoEvent>(10);

    // 主题
    private String topic;

    // 消息code
    private int msgCode;

    // 扩展参数
    private int other;

    // 回调返回数据
    private Object msgObj;

    public PhotoEvent() {
    }

    public PhotoEvent(String topic, int msgCode, int other, Object obj) {
        this.topic = topic;
        this.msgCode = msgCode;
        this.other = other;
        this.msgObj = obj;
    }

    public String getTopic() {
        return topic;
    }

    public PhotoEvent setTopic(String topic) {
        this.topic = topic;
        return this;
    }

    public int getMsgCode() {
        return msgCode;
    }

    public PhotoEvent setMsgCode(int msgCode) {
        this.msgCode = msgCode;
        return this;
    }

    public int getOtherCode() {
        return other;
    }

    public PhotoEvent setOtherCode(int resultCode) {
        this.other = resultCode;
        return this;
    }

    public Object getMsgObj() {
        return msgObj;
    }

    public PhotoEvent setMsgObj(Object obj) {
        this.msgObj = obj;
        return this;
    }

    /**
     * 恢复到默认状态
     */
    @Override
    public void reset() {
        this.topic = null;
        this.msgCode = 0;
        this.other = 0;
        this.msgObj = null;
    }

    public static PhotoEvent obtain() {
        PhotoEvent instance = sPool.acquire();
        return (instance != null) ? instance : new PhotoEvent();
    }

    public void recycle() {
        // Clear state if needed.
        reset();
        sPool.release(this);
    }

    public static void destory() {
        sPool = null;
    }
}
